package com.realtyManage.springboot.Controller;

import com.alibaba.fastjson.JSON;
import com.realtyManage.springboot.Model.Do.AppointmentIndex;
import com.realtyManage.springboot.Model.Do.Viki;
import com.realtyManage.springboot.Model.Vo.RegEntity;
import com.realtyManage.springboot.Service.AppointmentIndexService;
import com.realtyManage.springboot.Service.VikiService;
import com.realtyManage.springboot.Utils.SysExecRsUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.util.Date;

/**
 * AppointmentIndexController
 * 预约页面设置
 * @Author 杭州素色网络科技有限公司
 * @Date 2019/12/13
 **/

@Controller
@RequestMapping("/")
public class AppointmentIndexController {
    @Autowired
    private AppointmentIndexService appointmentIndexService;

    /**
     * 查询预约首页信息
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/queryAppointmentIndex",method = RequestMethod.GET)
    public String queryAppointmentIndex(HttpServletRequest request){
        return JSON.toJSONString(appointmentIndexService.queryAppointmentIndex());
    }

    /**
     * 修改预约信息
     * @param appointmentIndex
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/saveOrUpdateAppointmentIndex",method = RequestMethod.POST)
    private String saveOrUpdateAppointmentIndex(AppointmentIndex appointmentIndex, HttpServletRequest request) {
        Integer code = -1;
        AppointmentIndex ai = appointmentIndexService.getAppointmentIndex(appointmentIndex.getId());
        if (appointmentIndex.getAppointmentExplain() != null){
            ai.setAppointmentExplain(appointmentIndex.getAppointmentExplain());
        }
        if (appointmentIndex.getAppointmentImg() != null){
            ai.setAppointmentImg(appointmentIndex.getAppointmentImg());
        }
        if (appointmentIndex.getIndexImg() != null){
            ai.setIndexImg(appointmentIndex.getIndexImg());
        }
        if (appointmentIndex.getExplainImg() != null){
            ai.setExplainImg(appointmentIndex.getExplainImg());
        }
        if (appointmentIndexService.updateAppointmentIndex(ai) > 0){
            code = 1;
        }
        RegEntity re = new RegEntity();
        re.setInfoCode(code);
        re.setInfoText(SysExecRsUtil.getMsgFromCode(code));
        return JSON.toJSONString(re);
    }

}
